package isbnvalidation;

import exceptions.NotAValidISBNException;

public class ISBNValidator {
    // I guess there are better tools to do this outside, but I couldn t find them!
    private static ISBNValidator uniqueInstance = new ISBNValidator();

    public static ISBNValidator getInstance() {

        return uniqueInstance;
    }

    public boolean validatesISBN(final String anISBN) {
        synchronized (this) {
            switch (anISBN.length()) {
            case 10:
                ISBN10 isbn10 = new ISBN10(anISBN);
                return isbn10.hasCorrectChecksum();
            case 13:
                ISBN13 isbn13 = new ISBN13(anISBN);
                return isbn13.hasCorrectChecksum();
            default:
                throw new NotAValidISBNException("Unvalid ISBN lenght");
            }
        }
    }
}
